﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Hxsoft.AppV1;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.CommonPage
{
	public partial class SiteNavigation : System.Web.UI.Page
	{
		#region property
		/// <summary>
		/// 链接的地址。
		/// </summary>
		protected string LinkUrl
		{
			get
			{
				return Request["LinkUrl"];
			}
		}

		/// <summary>
		/// 站点标识的字段。
		/// </summary>
		protected string SiteIDQueryStringField
		{
			get
			{
				return Request["SiteIDQueryStringField"];
			}
		}

		/// <summary>
		/// 链接的目标。
		/// </summary>
		protected string LinkTarget
		{
			get
			{
				string linkTarget = Request["LinkTarget"];
				return string.IsNullOrEmpty(linkTarget) ? "ContentFrame" : linkTarget;
			}
		}

		/// <summary>
		/// 是否显示所有网站导航
		/// </summary>
		protected bool ShowAllSiteNav
		{
			get
			{
				bool showAllSiteNav = true;
				if (bool.TryParse(Request["ShowAllSiteNav"], out showAllSiteNav))
					return showAllSiteNav;
				return true;
			}
		}
		#endregion

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				this.DataBind();
				BindSiteData();
			}
		}

		/// <summary>
		/// 绑定站点数据。
		/// </summary>
		protected void BindSiteData()
		{
			List<Site> sites = Sites.GetItems();
			foreach (Hxsoft.AppV1.Module.Site site in sites)
			{
				if (!ManageRight(site.SiteId)) continue;
				TreeNode node = new TreeNode();
				node.Text = site.SiteName;
				node.NavigateUrl = LinkUrl + "?" + SiteIDQueryStringField + "=" + site.SiteId;
				node.Target = LinkTarget;

				SiteView.Nodes.Add(node);
			}

			if (ShowAllSiteNav)
				SiteView.Nodes.Add(new TreeNode("所有网站", null, null, LinkUrl + "?" + SiteIDQueryStringField + "=", LinkTarget));
		}		
		public virtual bool ManageRight(int? siteId)
		{
			return true;
		}
	}
}
